package com.nilcaream.dirstore.core.model;

/**
 * TODO
 * <p/>
 * Krzysztof Smigielski 7/13/13 9:08 PM
 */
public class ContentId implements Comparable {

    private String id;
    private long size;

    public ContentId(String id, long size) {
        this.id = id;
        this.size = size;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ContentId contentId = (ContentId) o;

        if (size != contentId.size) return false;
        if (id != null ? !id.equals(contentId.id) : contentId.id != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (int) (size ^ (size >>> 32));
        return result;
    }

    @Override
    public int compareTo(Object o) {
        if (o == null || o.getClass() != ContentId.class) {
            return Integer.MIN_VALUE;
        }

        return id.compareTo(((ContentId) o).id);
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("ContentId{");
        sb.append("id='").append(id).append('\'');
        sb.append(", size=").append(size);
        sb.append('}');
        return sb.toString();
    }
}
